package com.cet.designpatterns.observer.improvement;

import java.util.Objects;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-09-22 14:50
 **/
public class CurrentConditions implements Observer{

    private float temperature;
    private float pressure;
    private float humidity;

    @Override
    public void update(float temperature, float pressure, float humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        display();
    }

    public void display() {
        System.out.println("============CurrentCondition天气=============");
        System.out.println("***Today mTemperature: " + temperature + "***");
        System.out.println("***Today mPressure: " + pressure + "***");
        System.out.println("***Today mHumidity: " + humidity + "***");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof CurrentConditions)) {
            return false;
        }
        CurrentConditions that = (CurrentConditions) o;
        return Float.compare(that.temperature, temperature) == 0 &&
                Float.compare(that.pressure, pressure) == 0 &&
                Float.compare(that.humidity, humidity) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(temperature, pressure, humidity);
    }
}
